Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding model construction helpers #121

Merged
merged 11 commits into from
Apr 19, 2024
Merged

Adding model construction helpers #121

merged 11 commits into from
Apr 19, 2024

Conversation

ddsjoberg
Copy link
Collaborator

@ddsjoberg ddsjoberg commented Apr 16, 2024

What changes are proposed in this pull request?

  • Adding functions to assist in constructing models construct_model(), reformulate2() (similar to stats::reformulate() but adds backticks around variable names with spaces in them), bt() (adds backtics to variable as needed), and bt_strip() (removes backticks from character variable names).

I also updated ard_survey_svychisq() to use reformulate2() instead of stats::reformulate() which allows variable names with spaces in them. Other instances of stats::reformulate() should also be updated in the future.

The reason we're adding the constructors is because the full ARS (Analysis Result Standard) requires that we begin with a data frame, and these help us take a data frame, a response variable, and covariates to construct complex models.

Reference GitHub issue associated with pull request. e.g., 'closes #'
closes #108


Pre-review Checklist (if item does not apply, mark is as complete)

  • All GitHub Action workflows pass with a ✅
  • PR branch has pulled the most recent updates from master branch: usethis::pr_merge_main()
  • If a bug was fixed, a unit test was added.
  • If a new ard_*() function was added, it passes the ARD structural checks from cards::check_ard_structure().
  • Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): devtools::test_coverage()

Reviewer Checklist (if item does not apply, mark is as complete)

  • If a bug was fixed, a unit test was added.
  • Code coverage is suitable for any new functions/features: devtools::test_coverage()

When the branch is ready to be merged:

  • Update NEWS.md with the changes from this pull request under the heading "# cardx (development version)". If there is an issue associated with the pull request, reference it in parentheses at the end update (see NEWS.md for examples).
  • All GitHub Action workflows pass with a ✅
  • Approve Pull Request
  • Merge the PR. Please use "Squash and merge" or "Rebase and merge".

Copy link
Contributor

github-actions bot commented Apr 16, 2024

badge

Code Coverage Summary

Filename                        Stmts    Miss  Cover    Missing
----------------------------  -------  ------  -------  ------------------------------------
R/ard_aod_wald_test.R              77       8  89.61%   36-41, 91, 94
R/ard_car_anova.R                  45       2  95.56%   62, 65
R/ard_car_vif.R                    61       6  90.16%   37-40, 52, 86
R/ard_effectsize_cohens_d.R        88       2  97.73%   66, 111
R/ard_effectsize_hedges_g.R        82       2  97.56%   65, 115
R/ard_proportion_ci.R              42       5  88.10%   68-72
R/ard_regression_basic.R           15       1  93.33%   46
R/ard_regression.R                 50       0  100.00%
R/ard_smd_smd.R                    55       1  98.18%   48
R/ard_stats_anova.R                95       0  100.00%
R/ard_stats_aov.R                  36       0  100.00%
R/ard_stats_chisq_test.R           39       1  97.44%   39
R/ard_stats_fisher_test.R          41       1  97.56%   39
R/ard_stats_kruskal_test.R         35       1  97.14%   38
R/ard_stats_mcnemar_test.R         49       1  97.96%   43
R/ard_stats_mood_test.R            48       1  97.92%   46
R/ard_stats_oneway_test.R          31       0  100.00%
R/ard_stats_prop_test.R            82       1  98.78%   40
R/ard_stats_t_test.R              110       2  98.18%   62, 108
R/ard_stats_wilcox_test.R          97       2  97.94%   62, 114
R/ard_survey_svychisq.R            37       1  97.30%   44
R/ard_survey_svycontinuous.R      193       2  98.96%   169, 179
R/ard_survey_svyranktest.R         51       0  100.00%
R/ard_survey_svyttest.R            50       0  100.00%
R/ard_survival_survdiff.R          89       0  100.00%
R/ard_survival_survfit.R          180       8  95.56%   79-81, 85, 95-97, 247
R/construction_helpers.R           42       6  85.71%   113, 125-129
R/proportion_ci.R                 194      28  85.57%   290, 293, 302-307, 315, 330, 431-454
TOTAL                            2014      82  95.93%

Diff against main

Filename                    Stmts    Miss  Cover
------------------------  -------  ------  -------
R/ard_stats_anova.R            -9      -5  +4.81%
R/construction_helpers.R      +42      +6  +85.71%
TOTAL                         +33      +1  +0.02%

Results for commit: 531d054

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

github-actions bot commented Apr 16, 2024

Unit Tests Summary

  1 files   60 suites   8s ⏱️
 60 tests  40 ✅ 20 💤 0 ❌
164 runs  128 ✅ 36 💤 0 ❌

Results for commit 531d054.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Apr 16, 2024

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
construction_helpers 👶 $+0.29$ $+1$ $+1$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
construction_helpers 👶 $+0.29$ construct_model_works

Results for commit 37139ef

♻️ This comment has been updated with latest results.

@ddsjoberg
Copy link
Collaborator Author

ddsjoberg commented Apr 16, 2024

@shajoezhu @edelarua @ayogasekaram @Melkiades @zdz2101 I've added a function called reformulate2() in this PR. It is a simple wrapper for stats::reformulate() but will add backticks to your variable if is has a space in the variable name (the original function errors in this case).

Are there other characters that would require backticks to work properly?

@Melkiades
Copy link
Contributor

@shajoezhu @edelarua @ayogasekaram @Melkiades @zdz2101 I've added a function called reformulate2() in this PR. It is a simple wrapper for stats::reformulate() but will add backticks to your variable if is has a space in the variable name (the original function errors in this case).

Are there other characters that would require backticks to work properly?

The only other things I saw as special characters are \n and \r (but the latter was likely a typo, considering what it does, ahah). I suspect it would work nonetheless

@ddsjoberg
Copy link
Collaborator Author

Thanks @Melkiades ! I updated the default regex match to be bt(x, pattern = "[ \n\r]")

Copy link
Contributor

@ayogasekaram ayogasekaram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! Thanks @ddsjoberg

@ddsjoberg
Copy link
Collaborator Author

thank you @ayogasekaram !!

@ddsjoberg ddsjoberg merged commit 0c5fd0b into main Apr 19, 2024
28 checks passed
@ddsjoberg ddsjoberg deleted the 108-construct_model branch April 19, 2024 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate function to construct models?
3 participants